package com.lvcoding.auth2.auth.shizhan.verifycode.img;

import com.lvcoding.auth2.auth.shizhan.verifycode.parent.AbstractVerifyCodeHandler;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

import javax.imageio.ImageIO;

@Component
public class ImgVerifyCodeHandler extends AbstractVerifyCodeHandler<ImgCode> {

    @Override
    protected void sendCode(ServletWebRequest servletWebRequest, ImgCode verifyCode) throws Exception {
        assert servletWebRequest.getResponse() != null;
        ImageIO.write(verifyCode.getImage(), "JPEG", servletWebRequest.getResponse().getOutputStream());
    }
}
